<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.">
    <title>CoRs</title>
    <style>
        #result {
            width: 200px;
            height: 100px;
            border: solid 1px #90b;
        }
    </style>
</head>

<body>
    <button>发送请求</button>
    <div id="result"></div>

    <script>
        const btn = document.querySelector("button");
        const result = document.getElementById("result");
        const BASE_URL = "http://localhost:8000";
        btn.addEventListener('click', function () {
            const xhr = new XMLHttpRequest();
            xhr.open('get', BASE_URL + '/cors-server', true);
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        console.log(xhr.response);
                        result.innerHTML = xhr.response;
                    }
                }
            }
        });
    </script>
</body>

</html>